﻿using System;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using Brettle.Web.NeatUpload;
using QuickORM.BLL;
using QuickORM.Common;
using QuickORM.Entity;

public partial class Manage_WebPages_DevManage_Manager : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //DataTable dicTable = BLLFactory<T_DataDictionaryManager>.Instance.FindToDataTable("DictionaryType='ManagerType'");
        }
    }

    protected void btnok_Click(object sender, EventArgs e)
    {
        var js = "alert('操作失败！');";
        var manage = new T_ManagerInfo();
        manage.M_Type = Util.querySQL(dpManagerType.Text.Trim());
        manage.M_Time = DateTime.Now; //Convert.ToDateTime(Util.querySQL(txt_PressDate.Text.ToString()));
        manage.M_Content = Util.querySQL(txtContent.Text.Trim());
        manage.M_Chief = LoginUser.Instance.UserID; // Util.querySQL(txtFzr.Text.ToString().Trim());

        if (Encoding.Default.GetByteCount(txtContent.Text.Trim()) > 4000)
        {
            js = "alert('请输入少于4000个字符！');";
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "", js, true);
            return;
        }
        //新增
        var result = BLLFactory<T_ManagerInfoManager>.Instance.Insert2(manage);
        if (result > 0)
        {
            ///附件
            if (InputFile1.HasFile)
            {
                var FileName = InputFile1.FileName; //获取上传文件的文件名,包括后缀
                var ExtenName = Path.GetExtension(FileName); //获取扩展名
                var filePath = HttpContext.Current.Request.MapPath("~/UpLoadFiles/");
                var fileName = FileName.Substring(0, FileName.IndexOf('.')) + "_" + DateTime.Now.ToString("yyyyMMddhhmm") + ExtenName;
                var fileURL = Path.Combine(filePath, fileName);
                var fileURL2 = "~/UpLoadFiles/" + fileName; //Path.Combine(filePath, fileName);

                // 上传文件。
                InputFile1.MoveTo(fileURL, MoveToOptions.Overwrite);
                //更改文件数量
                manage.M_Attch = manage.M_Attch + 1;
                //保存 文件路径
                var acc = new T_SystemAccessorie();
                acc.ColName = "M_Attch";
                //  int id = BLLFactory<T_ManagerInfoManager>.Instance.FindLast().M_Id + 1;
                acc.DataID = result;
                acc.TableName = "T_Manage";
                acc.FileName = FileName;
                acc.FilePath = fileURL2;
                BLLFactory<T_SystemAccessorieManager>.Instance.Insert(acc); //插入数据库
            }
            js = "alert('新增成功！');window.opener.select();window.close();";
        }
        //if (BLLFactory<T_ManagerInfoManager>.Instance.Insert(manage))
        //{

        //}

        Page.ClientScript.RegisterClientScriptBlock(GetType(), "", js, true);
    }
}